package com.gp.library.utils;

/**
 * Created by jackdeng on 2021/4/13.
 */

public class DurationGuard {

    private long lastTimestamp = 0;
    private long threshold = 0;

    public DurationGuard(long threshold) {
        this.threshold = threshold;
    }

    public boolean checkAndUpdate(String tag) {
        long current = System.currentTimeMillis();
        if (current - lastTimestamp > threshold) {
            lastTimestamp = current;
            return true;
        }
        System.out.println("DurationGuard 任务被拦截........................." + tag);
        return false;
    }

    public boolean checkAndUpdate() {
        return checkAndUpdate("");
    }
}
